package com.gaofei.user.controller;

import com.gaofei.common.domain.User;
import com.gaofei.common.utils.JwtTokenUtil;
import com.gaofei.hr.interfaces.HrControllerFeign;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.management.remote.rmi._RMIConnection_Stub;
import java.util.HashMap;
import java.util.Map;

/**
 * @author : gaofee
 * @date : 11:45 2021/5/18
 * @码云地址 : https://gitee.com/itgaofee
 */
@RestController
@RequestMapping("user")
@Slf4j
@Api("APP用户操作相关的接口")
public class UserController {

    @Autowired
    HrControllerFeign hrControllerFeign;

    @RequestMapping(value = "/test")
    public String test(){
        String list = hrControllerFeign.list();
        return list;
    }


    //登录的逻辑
    @RequestMapping(value = "/login",method = RequestMethod.POST)
    @ApiOperation(value="用户登录",notes="账户和密码进行校验")
    public Object login(@RequestBody User portalUser){
        /*初始化用户名和密码*/
        User dbUser = new User();
        dbUser.setUsername("admin");
        dbUser.setPassword("123456");

        //相应的结果集
        Map<String, Object> result = new HashMap();
        //验证用户名和密码
        if(portalUser.getUsername().equals(dbUser.getUsername())&&portalUser.getPassword().equals(dbUser.getPassword())){
            JwtTokenUtil util = new JwtTokenUtil();
            String token = util.generateToken(dbUser);
            log.info("登录成功!!token是:{}",token);

            result.put("code", 200);
            result.put("token", token);
            result.put("message", "登录成功");
            return result;
        }
        result.put("code", 401);
        result.put("message", "登录失败");
        return result;
    }


    //方式1:远程调用普通传参方式
    /*@GetMapping ("hello")
    public String hello(@RequestParam("id") String id ){
        System.out.println(id+"===============");
        return "hello-user服务";
    }*/

    //restFul 风格来传参
//    @GetMapping ("hello/{id}/{id1}/{name}")
    @GetMapping ("hello/{id}")
    public String hello(@PathVariable("id") String id ){
        System.out.println(id+"===============");
        return "hello-user服务";
    }
}
